<?php
/**
 * Application level Controller
 *
 * This file is application-wide controller file. You can put all
 * application-wide controller-related methods here.
 *
 * PHP versions 4 and 5
 *
 * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
 * Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright     Copyright 2005-2010, Cake Software Foundation, Inc. (http://cakefoundation.org)
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       cake
 * @subpackage    cake.app
 */
class AppController extends Controller {
    var $components = array('Acl', 'Auth', 'Session', 'RequestHandler');
    var $helpers = array('Html', 'Form', 'Session', 'Javascript', 'Ajax');
    var $publicControllers = array('pages','detalles_actualizaciones','tipos_disposiciones','usuarios', 'areas_empresas');
    var $uses = array("Grupo");
     function isAuthorized() {
        return false;
    }
    
    function beforeFilter() {
        //Configure AuthComponent
        $this->Auth->userModel = 'Usuario';
        //$this->Auth->authorize = 'controller';
        $this->Auth->autoRedirect = true;
        $this->Auth->loginAction = array('controller' => 'usuarios', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'usuarios', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'usuarios', 'action' => 'home');
        $this->Auth->actionPath = 'controllers/';
        $this->Auth->allow('login','logout');
        $this->Auth->authorize = 'actions';
        if (in_array(low($this->params['controller']), $this->publicControllers)) {
            $this->Auth->allow();
        }
        $this->layout = "lsoft";
        App::import("Controller", "Usuarios");
        $usuarioC = new UsuariosController;
        
        $grupo_id = ($this->Auth->user("grupo_id"))? $this->Auth->user("grupo_id") : 0;    
       $menu = $usuarioC->generaMenu($grupo_id, $this->Auth->user("id"));
            $this->set(compact('grupo_id', 'menu'));  
        /*
        // Layout, dependiendo del NOMBRE del grupo al que pertenece el usuario
        $grupo = new Grupo();
        
        $grupo_id = ((($this->Auth->user("grupo_id"))) ? $this->Auth->user("grupo_id")  : 0);
        
        switch($grupo_id)
        {
            case 0 : 
                $this->layout = "lsoft";
                break;
                
            default:
                $nombreGrupo =  $grupo->query("select nombre from grupos where id = $grupo_id ");
                $nombreGrupo = $nombreGrupo[0]["grupos"]["nombre"];
                $this->layout = $nombreGrupo; 
                break;
        }
        */
        


    }
}
